package com.yuntongxun.ecdemo.voicechat.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.loopj.android.http.RequestParams;
import com.yuntongxun.ecdemo.R;
import com.yuntongxun.ecdemo.common.CCPAppManager;
import com.yuntongxun.ecdemo.common.utils.LogUtil;
import com.yuntongxun.ecdemo.common.utils.ToastUtil;
import com.yuntongxun.ecdemo.storage.ContactSqlManager;
import com.yuntongxun.ecdemo.ui.contact.ECContacts;
import com.yuntongxun.ecdemo.voicechat.api.ApiConstants;
import com.yuntongxun.ecdemo.voicechat.bean.PostResult;
import com.yuntongxun.ecdemo.voicechat.bean.UserInfo;
import com.yuntongxun.ecdemo.voicechat.comman.Contants;
import com.yuntongxun.ecdemo.voicechat.comman.EventBusTags;
import com.yuntongxun.ecdemo.voicechat.listeners.IRecyclerViewItemListener;
import com.yuntongxun.ecdemo.voicechat.listeners.LoadMoreClickListener;
import com.yuntongxun.ecdemo.voicechat.loading.ILoadView;
import com.yuntongxun.ecdemo.voicechat.loading.ILoadViewImpl;
import com.yuntongxun.ecdemo.voicechat.presenter.ICommonRequestPresenter;
import com.yuntongxun.ecdemo.voicechat.presenter.impl.CommonRequestPresenterImpl;
import com.yuntongxun.ecdemo.voicechat.ui.activity.GroupListActivity;
import com.yuntongxun.ecdemo.voicechat.ui.activity.SearchMembersActivity;
import com.yuntongxun.ecdemo.voicechat.ui.adapter.MemberAdapter;
import com.yuntongxun.ecdemo.voicechat.ui.services.MembersService;
import com.yuntongxun.ecdemo.voicechat.util.JsonHelper;
import com.yuntongxun.ecdemo.voicechat.util.NetUtils;
import com.yuntongxun.ecdemo.voicechat.util.iview.ICommonViewUi;
import com.yuntongxun.ecdemo.voicechat.view.headerfooterrecyclerview.ExStaggeredGridLayoutManager;
import com.yuntongxun.ecdemo.voicechat.view.headerfooterrecyclerview.HeaderAndFooterRecyclerViewAdapter;
import com.yuntongxun.ecdemo.voicechat.view.headerfooterrecyclerview.HeaderSpanSizeLookup;
import com.yuntongxun.ecdemo.voicechat.view.headerfooterrecyclerview.OnRecyclerViewScrollListener;
import com.yuntongxun.ecdemo.voicechat.view.headerfooterrecyclerview.RecyclerViewUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;

import static android.app.Activity.RESULT_OK;

/**
 * 会员
 *
 * @author li_zhuonan
 * @version 1.0
 * @since 2016/11/24
 */

public class MemberFragment extends BaseVoiceChatFragment implements ICommonViewUi, IRecyclerViewItemListener, LoadMoreClickListener, SwipeRefreshLayout.OnRefreshListener {

    @InjectView(R.id.group_by_tv)
    TextView groupByTv;
    @OnClick(R.id.group_by_select_layout)
    public void onSelectLayoutClick(){
        if(selectLayout.getVisibility()==View.VISIBLE){
            selectLayout.setVisibility(View.GONE);
        }else{
            selectLayout.setVisibility(View.VISIBLE);
        }
    }

    @InjectView(R.id.select_layout)
    LinearLayout selectLayout;

    @InjectView(R.id.defalut_select_img)
    ImageView defalutSelectImg;
    @InjectView(R.id.defalut_select_tv)
    TextView defalutSelectTv;
    @InjectView(R.id.default_layout)
    LinearLayout defaultLayout;
    @InjectView(R.id.name_select_img)
    ImageView nameSelectImg;
    @InjectView(R.id.name_select_tv)
    TextView nameSelectTv;
    @InjectView(R.id.name_layout)
    LinearLayout nameLayout;
    @InjectView(R.id.gender_select_img)
    ImageView genderSelectImg;
    @InjectView(R.id.gender_select_tv)
    TextView genderSelectTv;
    @InjectView(R.id.gender_layout)
    LinearLayout genderLayout;
    @InjectView(R.id.country_select_img)
    ImageView countrySelectImg;
    @InjectView(R.id.country_select_tv)
    TextView countrySelectTv;
    @InjectView(R.id.country_layout)
    LinearLayout countryLayout;
    @InjectView(R.id.age_select_img)
    ImageView ageSelectImg;
    @InjectView(R.id.age_select_tv)
    TextView ageSelectTv;
    @InjectView(R.id.age_layout)
    LinearLayout ageLayout;
    @InjectView(R.id.language_select_img)
    ImageView languageSelectImg;
    @InjectView(R.id.language_select_tv)
    TextView languageSelectTv;
    @InjectView(R.id.language_layout)
    LinearLayout languageLayout;
    private String mContent = "???";

    private static final String KEY_CONTENT = "MemberFragment:Content";

    @InjectView(R.id.swipe_refresh_layout)
    public SwipeRefreshLayout swipeRefreshLayout;

    @InjectView(R.id.recycler_view)
    public RecyclerView recyclerView;

    @InjectView(R.id.toolbar_back_btn)
    ImageButton backBtn;

    @InjectView(R.id.toolbar_title)
    TextView titleTv;

    @InjectView(R.id.toolbar_right_title)
    TextView rightTitle;

    @OnClick({R.id.refresh_again_btn,R.id.refresh_again_layout})
    public void onRefreshClick(){
        toRequest(ApiConstants.EventTags.REFRESH_LIST_EVENT);
    }

    @InjectView(R.id.refresh_again_layout)
    RelativeLayout refreshLayout;



    @OnClick(R.id.toolbar_right_title)
    public void onRightClick() {
        startActivity(new Intent(getActivity(), GroupListActivity.class));
    }

    private HeaderAndFooterRecyclerViewAdapter adapter;
    private ExStaggeredGridLayoutManager staggeredGridLayoutManager;
    private List<UserInfo> mResultList = new ArrayList<UserInfo>();

    private ICommonRequestPresenter iCommonRequestPresenter = null;

    private ILoadView iLoadView = null;

    private View loadMoreView = null;

    private boolean isRequesting = false;//标记，是否正在刷新

    private int mCurrentPage = 0;

    String orderBy="";

    String descAsc="";


    public static MemberFragment newInstance(String content) {
        MemberFragment fragment = new MemberFragment();
        fragment.mContent = content;

        return fragment;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString(KEY_CONTENT, mContent);
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)) {
            mContent = savedInstanceState.getString(KEY_CONTENT);
        }
    }

    @Override
    protected void onFirstUserVisible() {

    }


    @Override
    protected void onUserVisible() {

    }

    @Override
    protected void onUserInvisible() {

    }
    private Handler mHandler;
    @Override
    protected void initViewsAndEvents() {

        iCommonRequestPresenter = new CommonRequestPresenterImpl(mContext, this);

        iLoadView = new ILoadViewImpl(mContext, this);

        loadMoreView = iLoadView.inflate();
        backBtn.setVisibility(View.GONE);
        ButterKnife.findById(getActivity(), R.id.toolbar_title);
        titleTv.setText("Members");
        rightTitle.setText("Group");
        swipeRefreshLayout.setOnRefreshListener(this);
        recyclerView.addOnScrollListener(new MyScrollListener());

        refreshListView();

        //第一次进来时刷新
        if (NetUtils.isNetworkConnected(mContext)) {
            if (null != swipeRefreshLayout) {

                swipeRefreshLayout.postDelayed(new Runnable() {
                    @Override
                    public void run() {

                        swipeRefreshLayout.setRefreshing(true);

                        toRequest(ApiConstants.EventTags.REFRESH_LIST_EVENT);
                    }
                }, ApiConstants.Integers.PAGE_LAZY_LOAD_DELAY_TIME_MS);
            }
        }

        //每隔5分钟刷新在线状态
        mHandler = new Handler();
        mHandler.post(new Runnable() {
            @Override
            public void run()
            {
//                List<String> ids=new ArrayList<>();
//                for (int i=0;i<mResultList.size();i++){
//                    ids.add(mResultList.get(i).getId());
//                }
//                String[] array = new String[ids.size()];
//                ids.toArray(array);
//                asyncState(array);
                toRequest(ApiConstants.EventTags.ONLINE_STATE);
                mHandler.postDelayed(this, 15000);
            }
        });
    }

    public void refreshListView() {
        getActivity().startService(new Intent(getActivity(), MembersService.class));
        MemberAdapter mIntermediary = new MemberAdapter(mContext, mResultList, this);

        adapter = new HeaderAndFooterRecyclerViewAdapter(mIntermediary);

        recyclerView.setAdapter(adapter);

        if (mResultList.size() >= ApiConstants.Request.PAGE_NUMBER) {

            RecyclerViewUtils.setFooterView(recyclerView, loadMoreView);
        }
        staggeredGridLayoutManager = new ExStaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);

        staggeredGridLayoutManager.setSpanSizeLookup(new HeaderSpanSizeLookup((HeaderAndFooterRecyclerViewAdapter) recyclerView.getAdapter(), staggeredGridLayoutManager.getSpanCount()));

        recyclerView.setLayoutManager(staggeredGridLayoutManager);
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.fragment_member;
    }

    @Override
    protected boolean isBindEventBusHere() {
        return true;
    }

    public void onEvent(PostResult postResult){
        switch (postResult.getTag()){
            case EventBusTags.LOGOUT:
                getActivity().finish();
                break;
        }

    }

    @Override
    public void onRefresh() {
        toRequest(ApiConstants.EventTags.REFRESH_LIST_EVENT);
    }


    @Override
    public void toRequest(int eventTag) {
        if (eventTag == ApiConstants.EventTags.REFRESH_LIST_EVENT) {
            //刷新

            if (!NetUtils.isNetworkAvailable(mContext)) {
                showToastShort(Contants.NetStatus.NETDISABLE);
                swipeRefreshLayout.setRefreshing(false);
                refreshLayout.setVisibility(View.VISIBLE);
                return;
            }

            mCurrentPage = 1;

            RequestParams map = new RequestParams();
            map.put("page", "" + mCurrentPage);
            map.put("pageSize", "100");
            map.put("orderBy",orderBy);
            map.put("descAsc",descAsc);
            iCommonRequestPresenter.request(ApiConstants.EventTags.REFRESH_LIST_EVENT, mContext, ApiConstants.Urls.ACCOUNT_LIST, map);


        } else if (eventTag == ApiConstants.EventTags.LOAD_MORE_LIST_EVENT) {
            //加载更多

            if (isRequesting)
                return;

            if (!NetUtils.isNetworkAvailable(mContext)) {
                showToastShort(Contants.NetStatus.NETDISABLE);
                iLoadView.showErrorView(loadMoreView);
                return;
            }

            if (mResultList.size() < ApiConstants.Request.PAGE_NUMBER) {
                return;
            }

            mCurrentPage++;

            //iLoadView.showLoadingView(loadMoreView);

            RequestParams map = new RequestParams();
            map.put("page", "" + mCurrentPage);
            map.put("pageSize", "99999");
            map.put("orderBy",orderBy);
            map.put("descAsc",descAsc);

            iCommonRequestPresenter.request(ApiConstants.EventTags.LOAD_MORE_LIST_EVENT, mContext, ApiConstants.Urls.ACCOUNT_LIST, map);

            //iLoadView.showFinishView(loadMoreView);

        }else if(eventTag == ApiConstants.EventTags.ONLINE_STATE){
            if (!NetUtils.isNetworkAvailable(mContext)) {
                return;
            }
            RequestParams map = new RequestParams();
            map.put("page", ""+1);
            map.put("pageSize", "99999");
            iCommonRequestPresenter.request(ApiConstants.EventTags.ONLINE_STATE, mContext, ApiConstants.Urls.ACCOUNT_LIST, map);
        }
    }

    @Override
    public void getRequestData(int eventTag, String result) {
        if (eventTag == ApiConstants.EventTags.REFRESH_LIST_EVENT) {
            //下拉刷新

            List<UserInfo> resultList = parseResult(result);

            mResultList.clear();
            mResultList.addAll(resultList);
            List<String> ids=new ArrayList<>();
            for (int i=0;i<mResultList.size();i++){
                ids.add(mResultList.get(i).getId());
            }
            String[] array = new String[ids.size()];
            ids.toArray(array);


            List<ECContacts> contacts = new ArrayList<>();
            for (int i = 0; i < resultList.size(); i++) {
                ECContacts contact = new ECContacts();
                UserInfo info = mResultList.get(i);
                StringBuffer message= new StringBuffer();
                message.append("{\"result\":" );
                message.append("{\"accountName\":\"" + info.getAccountName() + "\",");
                message.append("\"nickName\":\"" + info.getNickName() + "\",");
                message.append("\"id\":\"" + info.getId() + "\",");
                message.append("\"gender\":\"" + info.getGender() + "\",");
                message.append("\"age\":\"" + info.getAge() + "\",");
                message.append("\"country\":\"" + info.getCountry() + "\",");
                message.append("\"nativeLanguage\":\"" + info.getNativeLanguage() + "\",");
                message.append("\"learningLanguage\":\"" + info.getLearningLanguage() + "\"}}");
//                LogUtil.e("memeber",message.toString());
//                String message = info.getNickName() + "-" + info.getGender() + "-" + info.getAge() + "-" + info.getCountry() + "-" + info.getNativeLanguage() + "-" + info.getLearningLanguage();
                contact.setNickname(mResultList.get(i).getNickName() + "(" + message.toString()+ ")");
                contact.setNickname(mResultList.get(i).getNickName() + "(" + message + ")");
                contact.setContactid(mResultList.get(i).getId());
                contacts.add(contact);
            }
            ContactSqlManager.insertContacts(contacts);
            refreshListView();
            refreshLayout.setVisibility(View.GONE);
//            asyncState(array);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    PostResult postResult = new PostResult();
                    postResult.setTag(EventBusTags.USER_DATA_NOTIFY);
                    postResult.setResult(mResultList);
                    EventBus.getDefault().post(postResult);
                }
            },1000);


        } else if (eventTag == ApiConstants.EventTags.LOAD_MORE_LIST_EVENT) {
            //加载更多

            List<UserInfo> resultList = parseResult(result);
            mResultList.addAll(resultList);
            List<String> ids=new ArrayList<>();
            for (int i=0;i<mResultList.size();i++){
                ids.add(mResultList.get(i).getId());
            }
            String[] array = new String[ids.size()];
            ids.toArray(array);
            List<ECContacts> contacts = new ArrayList<>();
            for (int i = 0; i < resultList.size(); i++) {
                ECContacts contact = new ECContacts();
                UserInfo info = mResultList.get(i);

                //{"userIp":null,"id":22,"accountName":"355833778@qq.com","nickName":"Milo","accountPwd":"xm123456789","gender":"男","age":19,"country":"China","nativeLanguage":"","learningLanguage":"",
                StringBuffer message= new StringBuffer();
                message.append("{\"result\":" );
                message.append("{\"accountName\":\"" + info.getAccountName() + "\",");
                message.append("\"nickName\":\"" + info.getNickName() + "\",");
                message.append("\"id\":\"" + info.getId() + "\",");
                message.append("\"gender\":\"" + info.getGender() + "\",");
                message.append("\"age\":\"" + info.getAge() + "\",");
                message.append("\"country\":\"" + info.getCountry() + "\",");
                message.append("\"nativeLanguage\":\"" + info.getNativeLanguage() + "\",");
                message.append("\"learningLanguage\":\"" + info.getLearningLanguage() + "\"}}");
                LogUtil.e("memeber",message.toString());
//                String message = info.getNickName() + "-" + info.getGender() + "-" + info.getAge() + "-" + info.getCountry() + "-" + info.getNativeLanguage() + "-" + info.getLearningLanguage();
                contact.setNickname(mResultList.get(i).getNickName() + "(" + message.toString()+ ")");
                contact.setContactid(mResultList.get(i).getId());
                contacts.add(contact);
            }

            ContactSqlManager.insertContacts(contacts);
            adapter.notifyDataSetChanged();
//            asyncState(array);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    PostResult postResult = new PostResult();
                    postResult.setTag(EventBusTags.USER_DATA_NOTIFY);
                    postResult.setResult(mResultList);
                    EventBus.getDefault().post(postResult);
                }
            },1000);

        }else if(eventTag == ApiConstants.EventTags.ONLINE_STATE){

            List<UserInfo> resultList = parseResult(result);
            for (int i=0;i<mResultList.size();i++){
                for (int j=0;j<resultList.size();j++){
                    if (mResultList.get(i).getAccountName().equals(resultList.get(j).getAccountName())){
                        mResultList.get(i).setOnLine(resultList.get(j).getOnLine());
                    }
                }
            }
            adapter.notifyDataSetChanged();
            PostResult postResult = new PostResult();
            postResult.setTag(EventBusTags.ONLINE_STATE);
            postResult.setResult(resultList);
            EventBus.getDefault().post(postResult);
        }
    }

    /**
     * 解析结果
     *
     * @param result
     * @return
     */
    public List<UserInfo> parseResult(String result) {
        JsonHelper<UserInfo> dataParser = new JsonHelper<UserInfo>(
                UserInfo.class);
        return dataParser.getDatas(
                result, "list");
    }

    @Override
    public void onRequestSuccessException(int eventTag, String msg) {

        if(eventTag==ApiConstants.EventTags.ONLINE_STATE){
            return;
        }

        if (eventTag==ApiConstants.EventTags.REFRESH_LIST_EVENT){
            refreshLayout.setVisibility(View.VISIBLE);
            return;
        }

        if (eventTag == ApiConstants.EventTags.LOAD_MORE_LIST_EVENT) {

            if (mCurrentPage > 1)
                mCurrentPage--;

            iLoadView.showErrorView(loadMoreView);
        }

        showToastShort(msg);
    }

    @Override
    public void onRequestFailureException(int eventTag, String msg) {
        if(eventTag==ApiConstants.EventTags.ONLINE_STATE){
            return;
        }

        if (eventTag==ApiConstants.EventTags.REFRESH_LIST_EVENT){
            refreshLayout.setVisibility(View.VISIBLE);
            return;
        }

        if (eventTag == ApiConstants.EventTags.LOAD_MORE_LIST_EVENT) {

            if (mCurrentPage > 1)
                mCurrentPage--;

            iLoadView.showErrorView(loadMoreView);
        }

        showToastShort(msg);
    }

    @Override
    public void isRequesting(int eventTag, boolean status) {
        if(eventTag==ApiConstants.EventTags.ONLINE_STATE){
            return;
        }
        isRequesting = status;
        if (!status) {
            swipeRefreshLayout.setRefreshing(false);
        }
    }


    @Override
    public void onItemClick(int position) {
        UserInfo info = mResultList.get(position);
        ECContacts mContacts = ContactSqlManager.getCacheContact(info.getId());
        if (mContacts == null) {
            mContacts = new ECContacts(info.getId());
            mContacts.setNickname(info.getNickName());
        }

        if (mContacts == null) {
            ToastUtil.showMessage(R.string.contact_none);
            return;
        }
//        String message=info.getNickName()+"-"+info.getGender()+"-"+info.getAge()+"-"+info.getCountry()+"-"+info.getNativeLanguage()+"-"+info.getLearningLanguage();
//        CCPAppManager.startChattingAction(getActivity(), mContacts.getContactid()+"("+message+")", mContacts.getNickname(), true);
        CCPAppManager.startChattingAction(getActivity(), mContacts.getContactid(), mContacts.getNickname(), true);
        getActivity().setResult(RESULT_OK);
    }

    @Override
    public void clickLoadMoreData() {
        toRequest(ApiConstants.EventTags.LOAD_MORE_LIST_EVENT);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.inject(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }

    public class MyScrollListener extends OnRecyclerViewScrollListener {

        @Override
        public void onScrollUp() {

        }

        @Override
        public void onScrollDown() {

        }

        @Override
        public void onBottom() {
            toRequest(ApiConstants.EventTags.LOAD_MORE_LIST_EVENT);
        }

        @Override
        public void onMoved(int distanceX, int distanceY) {

        }
    }

    @OnClick({R.id.default_layout,R.id.name_layout,R.id.gender_layout,R.id.country_layout,R.id.age_layout,R.id.language_layout,R.id.search_layout})
    public void onClick(View view){
        setDefaultLayout();
        switch (view.getId()){
            case R.id.default_layout:
                defalutSelectImg.setVisibility(View.VISIBLE);
                defalutSelectTv.setTextColor(getResources().getColor(R.color.voice_green));
                groupByTv.setText("Default");
                orderBy="";
                descAsc="";
                break;
            case R.id.name_layout:
                nameSelectImg.setVisibility(View.VISIBLE);
                nameSelectTv.setTextColor(getResources().getColor(R.color.voice_green));
                groupByTv.setText("Name");
                orderBy="nick_name";
                descAsc="asc";
                break;
            case R.id.gender_layout:
                genderSelectImg.setVisibility(View.VISIBLE);
                genderSelectTv.setTextColor(getResources().getColor(R.color.voice_green));
                groupByTv.setText("Gender");
                orderBy="gender";
                descAsc="";
                break;
            case R.id.country_layout:
                countrySelectImg.setVisibility(View.VISIBLE);
                countrySelectTv.setTextColor(getResources().getColor(R.color.voice_green));
                groupByTv.setText("Country");
                orderBy="country";
                descAsc="";
                break;
            case R.id.age_layout:
                ageSelectImg.setVisibility(View.VISIBLE);
                ageSelectTv.setTextColor(getResources().getColor(R.color.voice_green));
                groupByTv.setText("Age");
                orderBy="age";
                descAsc="asc";
                break;
            case R.id.language_layout:
                languageSelectImg.setVisibility(View.VISIBLE);
                languageSelectTv.setTextColor(getResources().getColor(R.color.normal_bg));
                groupByTv.setText("Language");
                orderBy="native_language";
                descAsc="";
                break;
            case R.id.search_layout:
                Intent intent = new Intent(mContext, SearchMembersActivity.class);
                startActivity(intent);
                break;
        }
        selectLayout.setVisibility(View.GONE);
        if (NetUtils.isNetworkConnected(mContext)) {
            if (null != swipeRefreshLayout) {

                swipeRefreshLayout.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        swipeRefreshLayout.setRefreshing(true);
                        toRequest(ApiConstants.EventTags.REFRESH_LIST_EVENT);
                    }
                }, ApiConstants.Integers.PAGE_LAZY_LOAD_DELAY_TIME_MS);
            }

        }

    }

    private void setDefaultLayout(){
        defalutSelectImg.setVisibility(View.INVISIBLE);
        defalutSelectTv.setTextColor(getResources().getColor(R.color.normal_bg));

        nameSelectImg.setVisibility(View.INVISIBLE);
        nameSelectTv.setTextColor(getResources().getColor(R.color.normal_bg));

        genderSelectImg.setVisibility(View.INVISIBLE);
        genderSelectTv.setTextColor(getResources().getColor(R.color.normal_bg));

        countrySelectImg.setVisibility(View.INVISIBLE);
        countrySelectTv.setTextColor(getResources().getColor(R.color.normal_bg));

        ageSelectImg.setVisibility(View.INVISIBLE);
        ageSelectTv.setTextColor(getResources().getColor(R.color.normal_bg));

        languageSelectImg.setVisibility(View.INVISIBLE);
        languageSelectTv.setTextColor(getResources().getColor(R.color.normal_bg));
    }


//    private void asyncState(String[] id){
//        if (id==null||id.length==0){
//            return;
//        }
//        ECDevice.getUsersState(id, new ECDevice.OnGetUsersStateListener() {
//            @Override
//            public void onGetUsersState(ECError ecError, ECUserState... ecUserStates) {
//                if (ecError.errorCode == SdkErrorCode.REQUEST_SUCCESS && ecUserStates != null) {
//                    for (int i=0;i<ecUserStates.length;i++){
//                        ECUserState userState =ecUserStates[i];
//                        for (int j=0;j<mResultList.size();j++){
//                            if (userState.getUserId().equals(mResultList.get(j).getId())){
//                                mResultList.get(j).setState(userState.isOnline()?0:1);
//                            }
//                        }
//                    }
//                    adapter.notifyDataSetChanged();
//                }
//            }
//        });
//    }



}
